package com.lcz.wanandroid.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.lcz.wanandroid.R;
import com.lcz.wanandroid.utils.ToastUtil;

public class ResgisterActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageView mIvReturn;
    private Toolbar mToolbar;
    /**
     * 邮箱/手机号
     */
    private EditText mUsername;
    /**
     * 输入密码
     */
    private EditText mPassword;
    /**
     * 确认密码
     */
    private EditText mPassword2;
    /**
     * 注册
     */
    private Button mRegister;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_resgister);
        initView();
    }

    private void initView() {
        mIvReturn = (ImageView) findViewById(R.id.iv_return);
        mIvReturn.setOnClickListener(this);
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mToolbar.setTitle("");
        setSupportActionBar(mToolbar);
        mUsername = (EditText) findViewById(R.id.username);
        mPassword = (EditText) findViewById(R.id.password);
        mPassword2 = (EditText) findViewById(R.id.password2);
        mRegister = (Button) findViewById(R.id.register);
        mRegister.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.iv_return:
                finish();
                break;
            case R.id.register:
                String username = mUsername.getText().toString().trim();
                String psw = mPassword.getText().toString().trim();
                String psw2 = mPassword2.getText().toString().trim();
                if(!TextUtils.isEmpty(username) &&!TextUtils.isEmpty(psw2) &&!TextUtils.isEmpty(psw) ){
                    if(psw.equals(psw2)){
                        Intent intent = getIntent();
                        intent.putExtra("use",username);
                        intent.putExtra("psw",psw);
                        setResult(200,intent);
                        finish();
                    }else{
                        ToastUtil.showShort("您输入两次密码不不一致~");
                    }
                }else{
                    ToastUtil.showShort("您输入的手机号或者密码不能为空~");
                }
                break;
        }
    }
}
